package com.aube.mis.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.springframework.stereotype.Service;

import com.aube.api.MessageVoService;
import com.aube.common.req.vo.PaginationReqVo;
import com.aube.common.resp.vo.PaginationRespVo;
import com.aube.mis.dto.DanmuDTO;
import com.aube.mis.dto.PaginationResultDTO;
import com.aube.mis.service.AbstractService;
import com.aube.mis.service.DanmuService;
import com.aube.mis.vo.DataTableCriterias;
import com.aube.support.ResultCode;
import com.aube.vo.MessageVo;

@Service
@SuppressWarnings("unchecked")
public class DanmuServiceImpl extends AbstractService implements DanmuService {
	@Resource
	private MessageVoService messageVoService;

	@Override
	public PaginationResultDTO<DanmuDTO> getDanmuList(DataTableCriterias criterias, String showId, String videoId, Long startTime, Long endTime) {
		PaginationReqVo<String> reqVo = fillPaginationInfo(criterias);
		reqVo.setReq(videoId);
		reqVo.setStartTime(startTime);
		reqVo.setEndTime(endTime);
		ResultCode<PaginationRespVo<MessageVo>> serverResp = messageVoService.messageList(reqVo);
		List<DanmuDTO> resultList = (List<DanmuDTO>) CollectionUtils.collect(serverResp.getRetval().getResp(), new Transformer() {

			@Override
			public DanmuDTO transform(Object object) {
				MessageVo messageVo = (MessageVo) object;
				DanmuDTO result = new DanmuDTO();
				result.setContent(messageVo.getContent());
				result.setMsgId(messageVo.getMsgId());
				result.setVideoTime(messageVo.getVideoTime());
				return result;
			}
		});
		PaginationResultDTO<DanmuDTO> result = new PaginationResultDTO<DanmuDTO>();
		result.setTotal(serverResp.getRetval().getTotal());
		result.setResultList(resultList);
		return result;
	}
}
